#!/bin/bash

# 备份原项目, 删除原项目, 从git clone新项目

time=$(date "+%Y%m%d-%H%M")
location=`pwd`
backup_file=${location}/backup_${time}_3d-curtain.zip


# 备份原项目
zip -r -q -o ${backup_file} ${location}/3d-curtain

if [ $? -eq 0 ]; then
    echo "1.备份成功!"
else
    echo "1.备份失败!"
    exit 0
fi

# 删除原项目
rm -rf ${location}/3d-curtain

if [ $? -eq 0 ]; then
    echo "2.删除原项目完成!"
else
    echo "2.删除原项目失败!"
    exit 0
fi

# clone project from git
git clone https://gitee.com/AmosWang/3d-curtain.git

if [ $? -eq 0 ]; then
    echo "3.从gitee上clone项目成功!"
else
    echo "3.从gitee上clone项目失败! 从备份回滚!"
    unzip ${backup_file}
    if [ $? -eq 0 ]; then
        echo "4.从备份回滚完成!"
    else
        echo "4.从备份回滚失败! 请手动处理!!!"
        echo ">>>>>>>>>更新项目失败!<<<<<<<<<<"
        exit 0
    fi
fi

echo ">>>>>>>>>更新项目成功!<<<<<<<<<<"
